package com.lanhai.mind.utils;

public class Tools {
	public static String byte2HexStr(byte[] b) {
		String hs = "";
		String stmp = "";
		for (int n = 0; n < b.length; n++) {
			stmp = (Integer.toHexString(b[n] & 0XFF));
			if (stmp.length() == 1)
				hs += " 0" + stmp;
			else
				hs += " " + stmp;  
		}
		return hs.toUpperCase().substring(1);
	}
	
	public static short toIntL(byte[] b) {
		short res = 0;
		for (int i = 0; i < b.length; i++) {
			res += (b[i] & 0xff) << (i * 8);
		}
		return res;
	}
	
	
	public static short toIntH(byte[] b){
		short res = 0;
	    for(int i=0;i<b.length;i++){
	        res += (b[i] & 0xff) << ((3-i)*8);
	    }
	    return res;
	}
	
}
